﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Data.SqlClient;

namespace DRSM
{
    public partial class AffectedCities : Form
    {

        private bool radiocheck = false;
        private bool medical = false;
        private bool military = false;
        private bool volunteer = false;
        private bool nameofcity = false;
        private bool noofpop = false;
        private bool notSimilarName = false;

        private bool updateNameOfCity = false;
        private bool updateNoOfPop = false;
        private bool updateRadioCheck = false;
        private bool updateMedical = false;
        private bool updateMilitary = false;
        private bool updateVolunteer = false;
        private bool updateNotSimilarName = false;

        public AffectedCities()
        {
            InitializeComponent();

            this.lblTime.Text = DateTime.Now.ToString();
            this.timer1.Start();
            this.timer2.Start();

            AutoCompleteStringCollection acsc = new AutoCompleteStringCollection();
            tbxUpdateAffectedCitySearch.AutoCompleteCustomSource = acsc;
            tbxUpdateAffectedCitySearch.AutoCompleteMode = AutoCompleteMode.Suggest;
            tbxUpdateAffectedCitySearch.AutoCompleteSource = AutoCompleteSource.CustomSource;

            pnlEmpty.Show();

            pnlAddNewAffectedCity.Hide();
            pnlAssignSupportPersonnelDetails1.Hide();
            pnlAssignSupportPersonnelDetails2.Hide();
            pnlAssignSupportToAffectedCity1.Hide();
            pnlAssignSupportToAffectedCity2.Hide();
            pnlDeleteYears.Hide();
            pnlDeleteAffectedCityDetails.Hide();
           // pnlDeleteSupportPersonnelDetails.Hide();
            pnlDeleteSupportPersonnelFromAffectedCity1.Hide();
            pnlUpdateAffectedCity.Hide();
            pnlUpdateAffectedCityDetails.Hide();
            pnlUpdateSupportPersonnel.Hide();
            pnlUpdateSupportPersonnelDetails.Hide();
            pnlViewCityProfile.Hide();
            //pnlViewCityProfileDetails.Hide();
            pnlViewSupportPersonnel.Hide();
            //pnlViewSupportPersonnelDetails.Hide();

            pnlDeleteMultiCity.Hide();
            pnlDeleteSingleCity.Hide();

            pnlDisplayListOfSupportPersonnelToBeAssigned.Hide();



        }

        private void btnPhysicalAid_Click(object sender, EventArgs e)
        {
            AllFormClass.pa.Show();
            this.Hide();
            //lblAddAffectedCity.BackColor = Color.FromArgb(240, 242, 244);
        }

        private void lblAddAffectedCity_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {


            // display add affected city pnl        
            pnlAddNewAffectedCity.Show();

            //hide all other pnl
            pnlEmpty.Hide();
            pnlAssignSupportPersonnelDetails1.Hide();
            pnlAssignSupportPersonnelDetails2.Hide();
            pnlAssignSupportToAffectedCity1.Hide();
            pnlAssignSupportToAffectedCity2.Hide();
            pnlDeleteYears.Hide();
            pnlDeleteAffectedCityDetails.Hide();
          //  pnlDeleteSupportPersonnelDetails.Hide();
            pnlDeleteSupportPersonnelFromAffectedCity1.Hide();
            pnlUpdateAffectedCity.Hide();
            pnlUpdateAffectedCityDetails.Hide();
            pnlUpdateSupportPersonnel.Hide();
            pnlUpdateSupportPersonnelDetails.Hide();
            pnlViewCityProfile.Hide();
            //pnlViewCityProfileDetails.Hide();
            pnlViewSupportPersonnel.Hide();
            //pnlViewSupportPersonnelDetails.Hide();

            pnlDeleteMultiCity.Hide();
            pnlDeleteSingleCity.Hide();

            pnlDisplayListOfSupportPersonnelToBeAssigned.Hide();


            //clear all textbox and reset all fields.
            tbxNameOfCity.Clear();
            tbxNoOfPopulation.Clear();
            radioBtnLow.Checked = false;
            radioBtnMedium.Checked = false;
            radioBtnHigh.Checked = false;
            tbxShortDescOfDamage.Clear();
            chkBxMilitary.Checked = false;
            chkBxMedical.Checked = false;
            chkBxVolunteer.Checked = false;
            CityAlrExisitError.Clear();

            tbxNameOfCity.Focus();


            //chkListBoxSupportPersonnelNeeded
            //chkListBoxSupportPersonnelNeeded.ClearSelected();        
        }

        //private void pnlAddNewAffectedCity_Paint(object sender, PaintEventArgs e)
        //{

        //}

        private void cbxUpdateSearch_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void manageAllPatientsDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void lblUpdateAffectedCity_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            

            //hide all other pnl
            pnlEmpty.Hide();
            pnlAddNewAffectedCity.Hide();
            pnlAssignSupportPersonnelDetails1.Hide();
            pnlAssignSupportPersonnelDetails2.Hide();
            pnlAssignSupportToAffectedCity1.Hide();
            pnlAssignSupportToAffectedCity2.Hide();
            pnlDeleteYears.Hide();
            pnlDeleteAffectedCityDetails.Hide();
           // pnlDeleteSupportPersonnelDetails.Hide();
            pnlDeleteSupportPersonnelFromAffectedCity1.Hide();
            
            pnlUpdateAffectedCityDetails.Hide();
            pnlUpdateSupportPersonnel.Hide();
            pnlUpdateSupportPersonnelDetails.Hide();
            pnlViewCityProfile.Hide();
            //pnlViewCityProfileDetails.Hide();
            pnlViewSupportPersonnel.Hide();
            //pnlViewSupportPersonnelDetails.Hide();

            pnlDeleteMultiCity.Hide();
            pnlDeleteSingleCity.Hide();

            pnlDisplayListOfSupportPersonnelToBeAssigned.Hide();

            //display update affected city pnl
            pnlUpdateAffectedCity.Show();

            //clear all textbox and reset field
            tbxUpdateAffectedCitySearch.Clear();           
            searchUpdateAffectedCityResult.ClearSelected();
            searchUpdateAffectedCityResult.Items.Clear();
            searchUpdateAffectedCityResult.Hide();


            tbxUpdateAffectedCitySearch.Focus();
            
        }

        private void lblDeleteAffectedCity_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            pnlDeleteYears.Show();

            pnlViewCityProfile.Hide();
            pnlAddNewAffectedCity.Hide();
            pnlAssignSupportPersonnelDetails1.Hide();
           // pnlAssignSupportPersonnelResult2.Hide();
            pnlAssignSupportToAffectedCity1.Hide();
            pnlAssignSupportToAffectedCity2.Hide();

            pnlDeleteSupportPersonnelFromAffectedCity1.Hide();
            //pnlSearchDeleteAffectedCityResult.Hide();
            //pnlSearchUpdateAffectedCityResult.Hide();
            pnlUpdateAffectedCity.Hide();
            //pnlViewCityProfileDetails.Hide();

            pnlAssignSupportPersonnelDetails1.Hide();
            pnlDeleteSupportPersonnelFromAffectedCity1.Hide();
            pnlUpdateSupportPersonnel.Hide();

        }

        private void lblViewCityProfile_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            pnlViewCityProfile.Show();
            pnlAddNewAffectedCity.Hide();
            pnlAssignSupportPersonnelDetails1.Hide();
           // pnlAssignSupportPersonnelResult2.Hide();
            pnlAssignSupportToAffectedCity1.Hide();
            pnlAssignSupportToAffectedCity2.Hide();
            pnlDeleteYears.Hide();
            pnlDeleteSupportPersonnelFromAffectedCity1.Hide();
            //pnlSearchDeleteAffectedCityResult.Hide();
            //pnlSearchUpdateAffectedCityResult.Hide();
            pnlUpdateAffectedCity.Hide();
            //pnlViewCityProfileDetails.Hide();

            pnlAssignSupportPersonnelDetails1.Hide();
            pnlDeleteSupportPersonnelFromAffectedCity1.Hide();
            pnlUpdateSupportPersonnel.Hide();

        }

        private void lblAssignSupportPersonnel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            pnlViewCityProfile.Hide();
            pnlDeleteYears.Hide();
            pnlUpdateAffectedCity.Hide();
            pnlAddNewAffectedCity.Hide();
            pnlAssignSupportPersonnelDetails1.Hide();
            //pnlAssignSupportPersonnelResult2.Hide();
            pnlAssignSupportToAffectedCity1.Show();
            pnlAssignSupportToAffectedCity2.Hide();

            pnlDeleteSupportPersonnelFromAffectedCity1.Hide();
            //pnlSearchDeleteAffectedCityResult.Hide();
            //pnlSearchUpdateAffectedCityResult.Hide();
            //pnlViewCityProfileDetails.Hide();
            pnlUpdateSupportPersonnel.Hide();
        }

        private void lblUpdateSupportPersonnel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            pnlViewCityProfile.Hide();
            pnlDeleteYears.Hide();
            pnlUpdateAffectedCity.Hide();
            pnlAddNewAffectedCity.Hide();
            pnlAssignSupportPersonnelDetails1.Hide();
            //pnlAssignSupportPersonnelResult2.Hide();
            pnlAssignSupportToAffectedCity1.Hide();
            pnlAssignSupportToAffectedCity2.Hide();

            pnlDeleteSupportPersonnelFromAffectedCity1.Hide();
            //pnlSearchDeleteAffectedCityResult.Hide();
            //pnlSearchUpdateAffectedCityResult.Hide();
            //pnlViewCityProfileDetails.Hide();
            pnlUpdateSupportPersonnel.Hide();
        }

        private void lblDeleteSupportPersonnel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            pnlViewCityProfile.Show();
            pnlDeleteYears.Hide();
            pnlUpdateAffectedCity.Hide();
            pnlAddNewAffectedCity.Hide();
            pnlAssignSupportPersonnelDetails1.Hide();
            //pnlAssignSupportPersonnelResult2.Hide();
            pnlAssignSupportToAffectedCity1.Hide();
            pnlAssignSupportToAffectedCity2.Hide();

            pnlDeleteSupportPersonnelFromAffectedCity1.Show();
            //pnlSearchDeleteAffectedCityResult.Hide();
            //pnlSearchUpdateAffectedCityResult.Hide();
            //pnlViewCityProfileDetails.Hide();
            pnlUpdateSupportPersonnel.Hide();
        }

        private void lblViewSupportPersonnel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            pnlViewCityProfile.Hide();
            pnlDeleteYears.Hide();
            pnlUpdateAffectedCity.Hide();
            pnlAddNewAffectedCity.Hide();
            pnlAssignSupportPersonnelDetails1.Hide();
           // pnlAssignSupportPersonnelResult2.Hide();
            pnlAssignSupportToAffectedCity1.Hide();
            pnlAssignSupportToAffectedCity2.Hide();

            pnlDeleteSupportPersonnelFromAffectedCity1.Hide();
            //pnlSearchDeleteAffectedCityResult.Hide();
            //pnlSearchUpdateAffectedCityResult.Hide();
            //pnlViewCityProfileDetails.Hide();
            pnlUpdateSupportPersonnel.Hide();
        }

        private void btnAffectedCities_Click(object sender, EventArgs e)
        {
            AllFormClass.ac.Show();
            this.Hide();
        }

        private void lblDeleteAffectedCity_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //display delect affected city pnl
            pnlDeleteYears.Show();

            //hide all other pnl
            pnlEmpty.Hide();
            pnlAddNewAffectedCity.Hide();
            pnlAssignSupportPersonnelDetails1.Hide();
            pnlAssignSupportPersonnelDetails2.Hide();
            pnlAssignSupportToAffectedCity1.Hide();
            pnlAssignSupportToAffectedCity2.Hide();
            
            pnlDeleteAffectedCityDetails.Hide();
          //  pnlDeleteSupportPersonnelDetails.Hide();
            pnlDeleteSupportPersonnelFromAffectedCity1.Hide();
            pnlUpdateAffectedCity.Hide();
            pnlUpdateAffectedCityDetails.Hide();
            pnlUpdateSupportPersonnel.Hide();
            pnlUpdateSupportPersonnelDetails.Hide();
            pnlViewCityProfile.Hide();
            //pnlViewCityProfileDetails.Hide();
            pnlViewSupportPersonnel.Hide();
            //pnlViewSupportPersonnelDetails.Hide();

            pnlDeleteMultiCity.Hide();
            pnlDeleteSingleCity.Hide();

            pnlDisplayListOfSupportPersonnelToBeAssigned.Hide();
            searchDeleteAffectedCityResult.Hide();

            //clear textbox and reset field
            tbxDeleteAffectedCitySearch.Clear();
            searchDeleteAffectedCityResult.ClearSelected();
            tbxSearchDGVDelAffectedCity.Clear();
            searchDeleteAffectedCityResult.Hide();

            radioBtnDelSingle.Checked = false;
            radioBtnDelMulti.Checked = false;

        }

        private void pbxHeader_Click(object sender, EventArgs e)
        {

        }

        private void lblViewCityProfile_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //display view city profile pnl
            pnlViewCityProfile.Show();
            
            //hide all other pnl
            pnlEmpty.Hide();
            pnlViewSupportPersonnel.Hide();
            pnlAddNewAffectedCity.Hide();
            pnlAssignSupportPersonnelDetails1.Hide();
            pnlAssignSupportPersonnelDetails2.Hide();
            pnlAssignSupportToAffectedCity1.Hide();
            pnlAssignSupportToAffectedCity2.Hide();
            pnlDeleteYears.Hide();
            pnlDeleteAffectedCityDetails.Hide();
          //  pnlDeleteSupportPersonnelDetails.Hide();
            pnlDeleteSupportPersonnelFromAffectedCity1.Hide();
            pnlUpdateAffectedCity.Hide();
            pnlUpdateAffectedCityDetails.Hide();
            pnlUpdateSupportPersonnel.Hide();
            pnlUpdateSupportPersonnelDetails.Hide();
            
           // pnlViewCityProfileDetails.Hide();
            pnlViewSupportPersonnel.Hide();
            //pnlViewSupportPersonnelDetails.Hide();

            
            pnlDeleteMultiCity.Hide();
            pnlDeleteSingleCity.Hide();


            pnlDisplayListOfSupportPersonnelToBeAssigned.Hide();

            tbxSearchViewCityProfile.Focus();

            //clear all textbox and reset field

            //try
            //{
            //    DGVViewCityProfile.DataSource = null;
            //    DGVViewCityProfile.Refresh();
            //    if (AllFormClass.AffectedCity.Count > 0)
            //    {
            //        DGVViewCityProfile.DataSource = AllFormClass.AffectedCity;
            //        DGVViewCityProfile.Refresh();
            //    }
            //}
            //catch (NullReferenceException nre)
            //{
            //    return;
            //}
            AffectedCityControl.viewCityProfile(DGVViewCityProfile);

        }

        private void lblAssignSupportPersonnel_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //show assign support personnel pnl
            pnlAssignSupportToAffectedCity2.Show();
            

            //hide all other pnl
            pnlEmpty.Hide();
            pnlAddNewAffectedCity.Hide();
            pnlAssignSupportPersonnelDetails1.Hide();
            pnlAssignSupportPersonnelDetails2.Hide();
            
            
            pnlDeleteYears.Hide();
            pnlDeleteAffectedCityDetails.Hide();
           // pnlDeleteSupportPersonnelDetails.Hide();
            pnlDeleteSupportPersonnelFromAffectedCity1.Hide();
            pnlUpdateAffectedCity.Hide();
            pnlUpdateAffectedCityDetails.Hide();
            pnlUpdateSupportPersonnel.Hide();
            pnlUpdateSupportPersonnelDetails.Hide();
            pnlViewCityProfile.Hide();
            //pnlViewCityProfileDetails.Hide();
            pnlViewSupportPersonnel.Hide();
            //pnlViewSupportPersonnelDetails.Hide();

            pnlAssignSupportToAffectedCity1.Hide();

            pnlDeleteMultiCity.Hide();
            pnlDeleteSingleCity.Hide();

            pnlDisplayListOfSupportPersonnelToBeAssigned.Hide();

            //clear all textbox and reset field
            tbxSearchAssignSupportPersonnel.Clear();
            lbxAssignSupportPersonnelResult1.ClearSelected();
            tbxSearchAssignAffectedCity.Clear();
            lbxAssignSupportPersonnelToCityResult2.ClearSelected();
            lbxAssignSupportPersonnelToCityResult2.Hide();

            tbxSearchAssignAffectedCity.Focus();
            
        }

        private void lblUpdateSupportPersonnel_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
        {

            //display update support personnel pnl
            pnlUpdateSupportPersonnel.Show();

            //hide all other pnl
            pnlEmpty.Hide();
            pnlAddNewAffectedCity.Hide();
            pnlAssignSupportPersonnelDetails1.Hide();
            pnlAssignSupportPersonnelDetails2.Hide();
            pnlAssignSupportToAffectedCity1.Hide();
            pnlAssignSupportToAffectedCity2.Hide();
            pnlDeleteYears.Hide();
            pnlDeleteAffectedCityDetails.Hide();
            //pnlDeleteSupportPersonnelDetails.Hide();
            pnlDeleteSupportPersonnelFromAffectedCity1.Hide();
            pnlUpdateAffectedCity.Hide();
            pnlUpdateAffectedCityDetails.Hide();
            
            pnlUpdateSupportPersonnelDetails.Hide();
            pnlViewCityProfile.Hide();
            //pnlViewCityProfileDetails.Hide();
            pnlViewSupportPersonnel.Hide();
            //pnlViewSupportPersonnelDetails.Hide();

            pnlDeleteMultiCity.Hide();
            pnlDeleteSingleCity.Hide();

            pnlDisplayListOfSupportPersonnelToBeAssigned.Hide();

            //clear all textbox and reset field
            tbxSupportPersonnelSearch.Clear();
            listBoxSearchUpdateSupportPersonnel.ClearSelected();

            if (tbxSupportPersonnelSearch.Text != String.Empty)
            {
                for (int i = 0; i < AllFormClass.SupportPersonnels.Count; i++)
                {
                    SupportPersonnels sp = (SupportPersonnels)AllFormClass.SupportPersonnels[i];
                    String searchItem = sp.NameOfPersonnel.ToString();
                    if (searchItem.Contains(tbxSupportPersonnelSearch.Text))
                    {
                        listBoxSearchUpdateSupportPersonnel.DisplayMember = "NameOfPersonnel";
                        listBoxSearchUpdateSupportPersonnel.Items.Add(sp.NameOfPersonnel);
                    }
                }
            }

            


        }

        private void lblViewSupportPersonnel_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //display view support personnel
            pnlViewSupportPersonnel.Show();

            //hide all other pnl
            pnlEmpty.Hide();
            pnlAddNewAffectedCity.Hide();
            pnlAssignSupportPersonnelDetails1.Hide();
            pnlAssignSupportPersonnelDetails2.Hide();
            pnlAssignSupportToAffectedCity1.Hide();
            pnlAssignSupportToAffectedCity2.Hide();
            pnlDeleteYears.Hide();
            pnlDeleteAffectedCityDetails.Hide();
           // pnlDeleteSupportPersonnelDetails.Hide();
            pnlDeleteSupportPersonnelFromAffectedCity1.Hide();
            pnlUpdateAffectedCity.Hide();
            pnlUpdateAffectedCityDetails.Hide();
            pnlUpdateSupportPersonnel.Hide();
            pnlUpdateSupportPersonnelDetails.Hide();
            pnlViewCityProfile.Hide();
            //pnlViewCityProfileDetails.Hide();
           // pnlViewSupportPersonnelDetails.Hide();
          
            //clear textbox and all other field
           // tbxViewSupportPersonnelSearch.Clear();
           // listBoxtbxViewSupportPersonnelResult.ClearSelected();
        }

        private void lblDeleteSupportPersonnel_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //display delete support personnel pnl
            pnlDeleteSupportPersonnelFromAffectedCity1.Show();

            //hide all other pnl
            pnlEmpty.Hide();
            pnlAddNewAffectedCity.Hide();
            pnlAssignSupportPersonnelDetails1.Hide();
            pnlAssignSupportPersonnelDetails2.Hide();
            pnlAssignSupportToAffectedCity1.Hide();
            pnlAssignSupportToAffectedCity2.Hide();
            pnlDeleteYears.Hide();
            pnlDeleteAffectedCityDetails.Hide();
            //pnlDeleteSupportPersonnelDetails.Hide();
            
            pnlUpdateAffectedCity.Hide();
            pnlUpdateAffectedCityDetails.Hide();
            pnlUpdateSupportPersonnel.Hide();
            pnlUpdateSupportPersonnelDetails.Hide();
            pnlViewCityProfile.Hide();
            //pnlViewCityProfileDetails.Hide();
            pnlViewSupportPersonnel.Hide();
            ////pnlViewSupportPersonnelDetails.Hide();

            pnlDeleteMultiCity.Hide();
            pnlDeleteSingleCity.Hide();

            pnlDisplayListOfSupportPersonnelToBeAssigned.Hide();

            //clear textbox and all other field
            tbxDeleteSupportPersonnelSearch.Clear();
            tbxDeleteSupportPersonnelSearch.Focus();
            //listBoxDeleteSupportPersonnelSearch.ClearSelected();

            //SupportPersonnels sp;
            //foreach (DataGridViewRow row in DGVDelSPfromAC.SelectedRows)
            //{
            //    int index = DGVDelSPfromAC.CurrentCell.RowIndex;
            //    sp  = (SupportPersonnels)AllFormClass.SupportPersonnels[index];
                
            
            //}
            try
            {
                DGVDelSPfromAC.DataSource = null;
                DGVDelSPfromAC.Refresh();
                if (AllFormClass.SupportPersonnels.Count > 0)
                {
                    foreach (SupportPersonnels s in AllFormClass.SupportPersonnels)
                    {
                        if (s.CityAssigned1 != "NILL")
                        {
                            AllFormClass.DelSPfromAC.Add(s);
                            DGVDelSPfromAC.DataSource = AllFormClass.DelSPfromAC;
                            DGVDelSPfromAC.Refresh();
                        }
                    }

                }
            }
            catch (NullReferenceException nre)
            {
                return;
            }




        }
        //################################################################################################################
        private void btnUpdateAffectedCitySearch_Click(object sender, EventArgs e)
        {
            
            //pnlSearchUpdateAffectedCityResult.Show();
            for (int i = 0; i < AllFormClass.AffectedCity.Count; i++)
            {
                AffectedCity a = (AffectedCity)AllFormClass.AffectedCity[i];
                string searchItem = a.NameOfCity.ToString();
                if (searchItem.Contains(tbxUpdateAffectedCitySearch.Text))
                {
                    searchUpdateAffectedCityResult.DisplayMember = "NameOfCity";
                    searchUpdateAffectedCityResult.Items.Add(AllFormClass.AffectedCity[i]);
                }
            }
        }

        private void btnDeleteAffectedCitySearch_Click(object sender, EventArgs e)
        {
            
        }

        private void chkListBoxSupportPersonnelNeeded_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void btnAffectedCities_Click_1(object sender, EventArgs e)
        {
           //pnlUpdateSupportPersonnel.Hide();
            pnlEmpty.Show();
        }

        //int count = 0; //comment out later

        private void btnAddCity_Click(object sender, EventArgs e)
        {
            //count++;
            //string nameOfCity = tbxNameOfCity.Text.Trim();
            //string NoOfPopulation = tbxNoOfPopulation.Text.Trim();
            //string ShortDescOfDamage = tbxShortDescOfDamage.Text.Trim();

            //char lvlOfDisaster = ' ';
            //if (radioBtnLow.Checked.Equals(true))
            //{
            //    lvlOfDisaster = 'L';
            //}
            //else if (radioBtnMedium.Checked.Equals(true))
            //{
            //    lvlOfDisaster = 'M';
            //}
            //else if (radioBtnHigh.Checked.Equals(true))
            //{
            //    lvlOfDisaster = 'H';
            //}

            ////@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
            //string supportPersonnelRequired = " ";
            //if (chkBxMedical.Checked.Equals(true))
            //{
            //    supportPersonnelRequired = "MEDICAL";
            //}
            //if (chkBxMilitary.Checked.Equals(true))
            //{
            //    supportPersonnelRequired = "MILITARY";
            //}
            //if (chkBxVolunteer.Checked.Equals(true))
            //{
            //    supportPersonnelRequired = "VOLUNTEER";
            //}
            //if (chkBxMedical.Checked.Equals(true) && chkBxMilitary.Checked.Equals(true))
            //{
            //    supportPersonnelRequired = "MEDICAL AND MILITARY";
            //}
            //if (chkBxMedical.Checked.Equals(true) && chkBxVolunteer.Checked.Equals(true))
            //{
            //    supportPersonnelRequired = "MEDICAL AND VOLUNTEER";
            //}
            //if (chkBxMilitary.Checked.Equals(true) && chkBxVolunteer.Checked.Equals(true))
            //{
            //    supportPersonnelRequired = "MILITARY AND VOLUNTEER";
            //}
            //if (chkBxMedical.Checked.Equals(true) && chkBxMilitary.Checked.Equals(true) && chkBxVolunteer.Checked.Equals(true))
            //{
            //    supportPersonnelRequired = "MEDICAL AND MILITARY AND VOLUNTEER";
            //}

            ////generate random number
            //int num = 10000;

            //num = num + count;

            ////if (AllFormClass.AffectedCity.Count > 0)
            ////{
            ////    num = 10000 + AllFormClass.AffectedCity.Count;
            ////}
            ////else
            ////{
            ////    num = 10000;
            ////}

            ////int num = (int)DateTime.Now.Ticks;


            ////AffectedCity ac = new AffectedCity(num, tbxNameOfCity.Text, tbxNoOfPopulation.Text, lvlOfDisaster, supportPersonnelRequired, tbxShortDescOfDamage.Text);
            ////AllFormClass.AffectedCity.Add(ac);

            
            AffectedCityControl.addcity( tbxNameOfCity, tbxNoOfPopulation, tbxShortDescOfDamage, radioBtnLow, radioBtnMedium, radioBtnHigh, chkBxMedical, chkBxMilitary, chkBxVolunteer);
           
            //dbmanager.addAffectedCity(num, tbxNameOfCity.Text, tbxNoOfPopulation.Text, lvlOfDisaster, supportPersonnelRequired, tbxShortDescOfDamage.Text);
            //dbmanager.addAffectedCity(num, nameOfCity, NoOfPopulation, lvlOfDisaster, supportPersonnelRequired, ShortDescOfDamage);
            
            //display success message to user
            MessageBox.Show("City Added Successfully!");

            //clear all textbox and reset field
            tbxNameOfCity.Clear();
            tbxNoOfPopulation.Clear();
            radioBtnLow.Checked = false;
            radioBtnMedium.Checked = false;
            radioBtnHigh.Checked = false;
            tbxShortDescOfDamage.Clear();
            chkBxMilitary.Checked = false;
            chkBxMedical.Checked = false;
            chkBxVolunteer.Checked = false;
 
        }

        //private void tbxViewCityProfileSearch_TextChanged(object sender, EventArgs e)
        //{
        //    pnlViewCityProfileDetails.Show();
        //    char firstChar = '0';
        //    this.ViewProfileSearchResult.Items.Clear();

        //    if (tbxViewCityProfileSearch.Text != String.Empty)
        //    {
        //        if (firstChar != tbxViewCityProfileSearch.Text[0])
        //        {
        //            firstChar = tbxViewCityProfileSearch.Text[0];

        //            for (int i = 0; i < AllFormClass.AffectedCity.Count; i++)
        //            {
        //                AffectedCity a = (AffectedCity)AllFormClass.AffectedCity[i];
        //                String searchItem = a.NameOfCity.ToString();
        //                if (searchItem[0] == firstChar)
        //                {
        //                    //ViewProfileSearchResult.DisplayMember = "NameOfCity";
        //                    //ViewProfileSearchResult.Items.Add(AllFormClass.AffectedCity[i]);
        //                    ViewProfileSearchResult.DisplayMember = "FirstName";
        //                    ViewProfileSearchResult.Items.Add(a.NameOfCity);

        //                    //searchUpdateAffectedCityResult.Items.Add(a.NameOfCity);
        //                }
        //            }
        //        }
        //    }
        //}

        //private void ViewProfileSearchResult_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        string selectedtitle = ViewProfileSearchResult.SelectedItem.ToString();
        //        foreach (AffectedCity AffectedCity in AllFormClass.AffectedCity)
        //        {
        //            if (AffectedCity.NameOfCity == selectedtitle)
        //            {
        //                lblViewNameOfCity.Text = AffectedCity.NameOfCity;
        //                lblViewPopulation.Text = AffectedCity.NoOfPopulation;
        //                lblViewShortDescOfDmg.Text = AffectedCity.ShortDescOfDmg;
        //                lblViewLvlOfDisasterImpact.Text = Convert.ToString(AffectedCity.LvlOfDisaster);
        //                lblViewSupportPersonnelRequired.Text = Convert.ToString(AffectedCity.SupportPersonnelNeeded);

        //            }
        //        }
        //    }
        //    catch (NullReferenceException nre)
        //    {
        //        return;
        //    }
            
        //}

        //private void pnlViewCityProfile_Paint(object sender, PaintEventArgs e)
        //{

        //}

        private void listBoxSearchUpdateSupportPersonnel_SelectedIndexChanged(object sender, EventArgs e)
        {
            String selectedItem = listBoxSearchUpdateSupportPersonnel.SelectedItem.ToString();

            foreach (SupportPersonnels supportpersonnels in AllFormClass.SupportPersonnels)
            {
                if (supportpersonnels.NameOfPersonnel == selectedItem)
                {
                    tbxUpdateSupportPersonnelName.Text = supportpersonnels.NameOfPersonnel;
                    tbxUpdateSupportPersonnelNRIC.Text = supportpersonnels.PersonnelIC;
                    tbxUpdateSupportPersonnelYearOfExp.Text = supportpersonnels.YearsOfExperience;
                    tbxUpdateSupportPersonnelAssignedAffectedCity.Text = supportpersonnels.CityAssigned1;
                    tbxUpdateSupprtPersonnelType.Text = supportpersonnels.ServiceProvided;


                }
            }
        }

        private void tbxSupportPersonnelSearch_TextChanged(object sender, EventArgs e)
        {
            this.listBox1.Items.Clear();
            listBoxSearchUpdateSupportPersonnel.Show();
            pnlUpdateSupportPersonnelDetails.Show();
            if (tbxSupportPersonnelSearch.Text != String.Empty)
            {
                for (int i = 0; i < AllFormClass.SupportPersonnels.Count; i++)
                {
                    SupportPersonnels sp = (SupportPersonnels)AllFormClass.SupportPersonnels[i];
                    String searchItem = sp.NameOfPersonnel.ToString();
                    if (searchItem.Contains(tbxSupportPersonnelSearch.Text))
                    {
                        listBox1.DisplayMember = "NameOfSupportPersonnel";
                        listBox1.Items.Add(sp.NameOfPersonnel);
                    }
                }
            }
        }

        private void btnSupportPersonnel_Click(object sender, EventArgs e)
        {
            AllFormClass.sp.Show();
            this.Hide();
        }

        private void tbxUpdateSupportPersonnelYearOfExp_TextChanged(object sender, EventArgs e)
        {

        }

        //private void btnViewSearch_Click(object sender, EventArgs e)
        //{
        //    pnlViewCityProfileDetails.Show();
        //    for (int i = 0; i < AllFormClass.AffectedCity.Count; i++)
        //    {
        //        AffectedCity a = (AffectedCity)AllFormClass.AffectedCity[i];
        //        String searchItem = a.NameOfCity.ToString();
        //        if (searchItem.Contains(tbxViewCityProfileSearch.Text))
        //        {
        //            ViewProfileSearchResult.DisplayMember = "FirstName";
        //            ViewProfileSearchResult.Items.Add(a.NameOfCity);
        //        }

        //    }
        //}
        //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        private void tbxNameOfCity_TextChanged(object sender, EventArgs e)
        {
            nameofcity = tbxNameOfCity.Text != "";
            if (notSimilarName && nameofcity && noofpop && radiocheck && (military || volunteer || medical))
            {
                this.btnAddCity.Enabled = true;
            }
            else
            {
                this.btnAddCity.Enabled = false;
            }
        }

        private void tbxNoOfPopulation_TextChanged(object sender, EventArgs e)
        {
            noofpop = tbxNoOfPopulation.Text != "";
            if (notSimilarName && nameofcity && noofpop && radiocheck && (military || volunteer || medical))
            {
                this.btnAddCity.Enabled = true;
            }
            else
            {
                this.btnAddCity.Enabled = false;
            }
        }

        private void radioBtnLow_CheckedChanged(object sender, EventArgs e)
        {
            radiocheck = true;
            if (notSimilarName && nameofcity && noofpop && radiocheck && (military || volunteer || medical))
            {
                this.btnAddCity.Enabled = true;
            }
            else
            {
                this.btnAddCity.Enabled = false;
            }
        }

        private void radioBtnMedium_CheckedChanged(object sender, EventArgs e)
        {
            radiocheck = true;
            if (notSimilarName && nameofcity && noofpop && radiocheck && (military || volunteer || medical))
            {
                this.btnAddCity.Enabled = true;
            }
            else
            {
                this.btnAddCity.Enabled = false;
            }
        }

        private void radioBtnHigh_CheckedChanged(object sender, EventArgs e)
        {
            radiocheck = true;
            if (notSimilarName && nameofcity && noofpop && radiocheck && (military || volunteer || medical))
            {
                this.btnAddCity.Enabled = true;
            }
            else
            {
                this.btnAddCity.Enabled = false;
            }
        }

        private void chkBxMedical_CheckedChanged(object sender, EventArgs e)
        {
            medical = chkBxMedical.Checked;
            if (notSimilarName && nameofcity && noofpop && radiocheck && (military || volunteer || medical))
            {
                this.btnAddCity.Enabled = true;
            }
            else
            {
                this.btnAddCity.Enabled = false;
            }
        }

        private void chkBxMilitary_CheckedChanged(object sender, EventArgs e)
        {
            military = chkBxMilitary.Checked;
            if (notSimilarName && nameofcity && noofpop && radiocheck && (military || volunteer || medical))
            {
                this.btnAddCity.Enabled = true;
            }
            else
            {
                this.btnAddCity.Enabled = false;
            }
        }

        private void chkBxVolunteer_CheckedChanged(object sender, EventArgs e)
        {
            volunteer = chkBxVolunteer.Checked;
            if (notSimilarName && nameofcity && noofpop && radiocheck && (military || volunteer || medical))
            {
                this.btnAddCity.Enabled = true;
            }
            else
            {
                this.btnAddCity.Enabled = false;
            }
        }
        // Boolean flag used to determine when a character other than a number is entered.
        private bool nonNumberEntered = false;

        private void tbxNoOfPopulation_KeyDown(object sender, KeyEventArgs e)
        {
            // Initialize the flag to false.
            nonNumberEntered = false;

            // Determine whether the keystroke is a number from the top of the keyboard.
            if (e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9)
            {
                // Determine whether the keystroke is a number from the keypad.
                if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
                {
                    // Determine whether the keystroke is a backspace.
                    if (e.KeyCode != Keys.Back)
                    {
                        // A non-numerical keystroke was pressed.
                        // Set the flag to true and evaluate in KeyPress event.
                        nonNumberEntered = true;
                    }
                }
            }
            //If shift key was pressed, it's not a number.
            if (Control.ModifierKeys == Keys.Shift)
            {
                nonNumberEntered = true;
            }

        }

        private void tbxNoOfPopulation_KeyPress(object sender, KeyPressEventArgs e)
        {
            // Check for the flag being set in the KeyDown event.
            if (nonNumberEntered == true)
            {
                // Stop the character from being entered into the control since it is non-numerical.
                e.Handled = true;
            }

        }
        private bool nonLetterEntered = false;

        private void tbxNameOfCity_KeyDown(object sender, KeyEventArgs e)
        {
            // Initialize the flag to false.
            nonLetterEntered = false;

            // Determine whether the keystroke is a number from the top of the keyboard.
            if (e.KeyCode < Keys.A || e.KeyCode > Keys.Z )
            {
                //// Determine whether the keystroke is a number from the keypad.
                //if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
                //{
                if (e.KeyCode != Keys.Space)
                {
                    // Determine whether the keystroke is a backspace.
                    if (e.KeyCode != Keys.Back)
                    {
                        // A non-numerical keystroke was pressed.
                        // Set the flag to true and evaluate in KeyPress event.
                        nonLetterEntered = true;
                    }
                }

                //}
            }
            //If shift key was pressed, it's not a number.
            if (Control.ModifierKeys == Keys.Shift)
            {
                nonLetterEntered = true;
            }

        }

        private void tbxNameOfCity_KeyPress(object sender, KeyPressEventArgs e)
        {
            // Check for the flag being set in the KeyDown event.
            if (nonLetterEntered == true)
            {
                // Stop the character from being entered into the control since it is non-numerical.
                e.Handled = true;
            }

        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            tbxNameOfCity.Clear();
            tbxNoOfPopulation.Clear();
            radioBtnLow.Checked = false;
            radioBtnMedium.Checked = false;
            radioBtnHigh.Checked = false;
            tbxShortDescOfDamage.Clear();
            chkBxMilitary.Checked = false;
            chkBxMedical.Checked = false;
            chkBxVolunteer.Checked = false;
        }

        private void btnSelectUpdateCity_Click(object sender, EventArgs e)
        {
            chkbxUpdateMedical.Checked = false;
            chkbxUpdateMilitary.Checked = false;
            chkbxUpdateVolunteer.Checked = false;
            String selectedItem = searchUpdateAffectedCityResult.SelectedItem.ToString();

            foreach (AffectedCity AffectedCity in AllFormClass.AffectedCity )
                if (AffectedCity.NameOfCity == selectedItem)
                {
                    tbxUpdateNameOfCity.Text = AffectedCity.NameOfCity;
                }
           // AffectedCity ac = (AffectedCity)searchUpdateAffectedCityResult.SelectedItem;

            //tbxUpdateNameOfCity.Text = ac.NameOfCity;
            //tbxUpdateNoOfPopulation.Text = ac.NoOfPopulation;
            //tbxUpdateDescOfDmg.Text = ac.ShortDescOfDmg;
            //if (ac.LvlOfDisaster.Equals('L'))
            //{
            //    radioBtnUpdateLow.Select();
            //}
            //else if (ac.LvlOfDisaster.Equals('M'))
            //{
            //    radioBtnUpdateMedium.Select();
            //}
            //else if (ac.LvlOfDisaster.Equals('H'))
            //{
            //    radioBtnUpdateHigh.Select();
            //}

            //if (ac.SupportPersonnelNeeded.Equals("Medical"))
            //{
            //    chkbxUpdateMedical.Checked = true;
            //}
            //else if (ac.SupportPersonnelNeeded.Equals("Military"))
            //{
            //    chkbxUpdateMilitary.Checked = true;
            //}
            //else if (ac.SupportPersonnelNeeded.Equals("Volunteer"))
            //{
            //    chkbxUpdateVolunteer.Checked = true;
            //}
            //else if (ac.SupportPersonnelNeeded.Equals("Medical and Military"))
            //{
            //    chkbxUpdateMedical.Checked = true;
            //    chkbxUpdateMilitary.Checked = true;
            //}
            //else if (ac.SupportPersonnelNeeded.Equals("Medical and Volunteer"))
            //{
            //    chkbxUpdateMedical.Checked = true;
            //    chkbxUpdateVolunteer.Checked = true;
            //}
            //else if (ac.SupportPersonnelNeeded.Equals("Military and Volunteer"))
            //{
            //    chkbxUpdateMilitary.Checked = true;
            //    chkbxUpdateVolunteer.Checked = true;
            //}
            //else if (ac.SupportPersonnelNeeded.Equals("Medical and Military and Volunteer"))
            //{
            //    chkbxUpdateMedical.Checked = true;
            //    chkbxUpdateMilitary.Checked = true;
            //    chkbxUpdateVolunteer.Checked = true;
            //}
            pnlUpdateAffectedCityDetails.Show();

        }

       

        private void tbxUpdateAffectedCitySearch_TextChanged(object sender, EventArgs e)
        {
            AffectedCityControl.viewUpdate(tbxUpdateAffectedCitySearch);
            //char firstChar = '0';
            //this.searchUpdateAffectedCityResult.Items.Clear();

            //if (tbxUpdateAffectedCitySearch.Text != String.Empty)
            //{
            //    if (firstChar != tbxUpdateAffectedCitySearch.Text[0])
            //    {
            //        firstChar = tbxUpdateAffectedCitySearch.Text[0];

            //        for (int i = 0; i < AllFormClass.AffectedCity.Count; i++)
            //        {
            //            AffectedCity a = (AffectedCity)AllFormClass.AffectedCity[i];
            //            String searchItem = a.NameOfCity.ToString();
            //            if (searchItem[0] == firstChar)
            //            {
            //                searchUpdateAffectedCityResult.DisplayMember = "NameOfCity";
            //                searchUpdateAffectedCityResult.Items.Add(AllFormClass.AffectedCity[i]);
            //                //searchUpdateAffectedCityResult.Items.Add(a.NameOfCity);
            //            }
            //        }
            //    }
            //}
            searchUpdateAffectedCityResult.Show();
            this.searchUpdateAffectedCityResult.Items.Clear();

            if (tbxUpdateAffectedCitySearch.Text != String.Empty)
            {
                for (int i = 0; i < AllFormClass.AffectedCity.Count; i++)
                {
                    AffectedCity a = (AffectedCity)AllFormClass.AffectedCity[i];
                    String searchItem = a.NameOfCity.ToString();
                    if (searchItem.Contains(tbxUpdateAffectedCitySearch.Text))
                    {
                        searchUpdateAffectedCityResult.DisplayMember = "NameOfCity";
                        searchUpdateAffectedCityResult.Items.Add(a.NameOfCity);
                    }
                }

            }

        }

        private void tbxDeleteAffectedCitySearch_TextChanged(object sender, EventArgs e)
        {
            searchDeleteAffectedCityResult.Show();
            AffectedCityControl.view(tbxDeleteAffectedCitySearch);
            //char firstChar = '0';
            //this.searchDeleteAffectedCityResult.Items.Clear();

            //if (tbxDeleteAffectedCitySearch.Text != String.Empty)
            //{
            //    if (firstChar != tbxDeleteAffectedCitySearch.Text[0])
            //    {
            //        firstChar = tbxDeleteAffectedCitySearch.Text[0];

            //        for (int i = 0; i < AllFormClass.AffectedCity.Count; i++)
            //        {
            //            AffectedCity a = (AffectedCity)AllFormClass.AffectedCity[i];
            //            String searchItem = a.NameOfCity.ToString();
            //            if (searchItem[0] == firstChar)
            //            {
            //                searchDeleteAffectedCityResult.DisplayMember = "FirstName";
            //                searchDeleteAffectedCityResult.Items.Add(a.NameOfCity);
            //                //searchUpdateAffectedCityResult.Items.Add(a.NameOfCity);
            //            }
            //        }
            //    }
            //}

            this.searchDeleteAffectedCityResult.Items.Clear();
            if (tbxDeleteAffectedCitySearch.Text != String.Empty)
            {
                for (int i = 0; i < AllFormClass.AffectedCity.Count; i++)
                {
                    AffectedCity a = (AffectedCity)AllFormClass.AffectedCity[i];
                    String searchItem = a.NameOfCity.ToString();
                    if (searchItem.Contains(tbxDeleteAffectedCitySearch.Text))
                    {
                        searchDeleteAffectedCityResult.DisplayMember = "NameOfCity";
                        searchDeleteAffectedCityResult.Items.Add(a.NameOfCity);
                    }
                }
            }
        }

        private void btnSelectDeleteAffectedCity_Click(object sender, EventArgs e)
        {

        }

        private void searchDeleteAffectedCityResult_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (searchDeleteAffectedCityResult.SelectedItem != null)
            {
                pnlDeleteAffectedCityDetails.Show();
                string selectedtitle = searchDeleteAffectedCityResult.SelectedItem.ToString();
                foreach (AffectedCity AffectedCity in AllFormClass.AffectedCity)
                {
                    if (AffectedCity.NameOfCity == selectedtitle)
                    {
                        lblDeleteCityID.Text = Convert.ToString(AffectedCity.CityID1);
                        lblDeleteCityName.Text = AffectedCity.NameOfCity;
                        lblDeletePopulation.Text = AffectedCity.NoOfPopulation;
                        lblDeleteDescOfDmg.Text = AffectedCity.ShortDescOfDmg;
                        lblDeleteLvlofDisasterImpact.Text = Convert.ToString(AffectedCity.LvlOfDisaster);
                        lblDeleteRequiredPersonnel.Text = Convert.ToString(AffectedCity.SupportPersonnelNeeded);

                    }
                }
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            //string selectedtitle = searchDeleteAffectedCityResult.SelectedItem.ToString();
            //for (int i = 0; i < AllFormClass.AffectedCity.Count; i++)
            //{
            //    AffectedCity a = (AffectedCity)AllFormClass.AffectedCity[i];
            //    if (a.NameOfCity == selectedtitle)
            //    {
            //        AllFormClass.AffectedCity.RemoveAt(i);
                    
            //        MessageBox.Show("City removed successfully!");
            //        tbxDeleteAffectedCitySearch.Clear();
            //        pnlDeleteAffectedCityDetails.Hide();
                    
            //    }
            //}
            ////AllFormClass.AffectedCity.Remove(ac);
            AffectedCityControl.deleteSingleAffectedCity(searchDeleteAffectedCityResult, tbxDeleteAffectedCitySearch, pnlDeleteAffectedCityDetails);
        }

        private void pnlUpdateAffectedCity_Paint(object sender, PaintEventArgs e)
        {

        }

        private void searchUpdateAffectedCityResult_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                String selectedItem = searchUpdateAffectedCityResult.SelectedItem.ToString();

                foreach (AffectedCity AffectedCity in AllFormClass.AffectedCity)
                    if (AffectedCity.NameOfCity == selectedItem)
                    {
                        tbxUpdateCityId.Text = Convert.ToString(AffectedCity.CityID1);
                        tbxUpdateNameOfCity.Text = AffectedCity.NameOfCity;
                        tbxUpdateNoOfPopulation.Text = AffectedCity.NoOfPopulation;
                        tbxUpdateDescOfDmg.Text = AffectedCity.ShortDescOfDmg;
                        if (AffectedCity.LvlOfDisaster.Equals('L'))
                        {
                            radioBtnUpdateLow.Select();
                        }
                        else if (AffectedCity.LvlOfDisaster.Equals('M'))
                        {
                            radioBtnUpdateMedium.Select();
                        }
                        else if (AffectedCity.LvlOfDisaster.Equals('H'))
                        {
                            radioBtnUpdateHigh.Select();
                        }

                        if (AffectedCity.SupportPersonnelNeeded.Equals("MEDICAL"))
                        {
                            chkbxUpdateMedical.Checked = true;
                        }
                        else if (AffectedCity.SupportPersonnelNeeded.Equals("MILITARY"))
                        {
                            chkbxUpdateMilitary.Checked = true;
                        }
                        else if (AffectedCity.SupportPersonnelNeeded.Equals("VOLUNTEER"))
                        {
                            chkbxUpdateVolunteer.Checked = true;
                        }
                        else if (AffectedCity.SupportPersonnelNeeded.Equals("MEDICAL AND MILITARY"))
                        {
                            chkbxUpdateMedical.Checked = true;
                            chkbxUpdateMilitary.Checked = true;
                        }
                        else if (AffectedCity.SupportPersonnelNeeded.Equals("MEDICAL AND VOLUNTEER"))
                        {
                            chkbxUpdateMedical.Checked = true;
                            chkbxUpdateVolunteer.Checked = true;
                        }
                        else if (AffectedCity.SupportPersonnelNeeded.Equals("MILITARY AND VOLUNTEER"))
                        {
                            chkbxUpdateMilitary.Checked = true;
                            chkbxUpdateVolunteer.Checked = true;
                        }
                        else if (AffectedCity.SupportPersonnelNeeded.Equals("MEDICAL AND MILITARY AND VOLUNTEER"))
                        {
                            chkbxUpdateMedical.Checked = true;
                            chkbxUpdateMilitary.Checked = true;
                            chkbxUpdateVolunteer.Checked = true;
                        }
                    }
                pnlUpdateAffectedCityDetails.Show();
            }
            catch (NullReferenceException nre)
            {
                return;
            }
        }

        private void btnUpdateCity_Click(object sender, EventArgs e)
        {
            //foreach (AffectedCity AffectedCity in AllFormClass.AffectedCity)
            //{
            //    if (Convert.ToString(AffectedCity.CityID1) == tbxUpdateCityId.Text)
            //    {
            //        AffectedCity.CityID1 = Convert.ToInt32(tbxUpdateCityId.Text);
            //        AffectedCity.NameOfCity = tbxUpdateNameOfCity.Text;
            //        AffectedCity.NoOfPopulation = tbxUpdateNoOfPopulation.Text;
            //        AffectedCity.ShortDescOfDmg = tbxUpdateDescOfDmg.Text;

            //        if (radioBtnUpdateLow.Checked.Equals(true))
            //        {
            //            AffectedCity.LvlOfDisaster = 'L';
            //        }
            //        else if (radioBtnUpdateMedium.Checked.Equals(true))
            //        {
            //            AffectedCity.LvlOfDisaster = 'M';
            //        }
            //        else if (radioBtnUpdateHigh.Checked.Equals(true))
            //        {
            //            AffectedCity.LvlOfDisaster = 'H';
            //        }

            //        if (chkbxUpdateMedical.Checked.Equals(true))
            //        {
            //            AffectedCity.SupportPersonnelNeeded = "MEDICAL";
            //        }
            //        if (chkbxUpdateMilitary.Checked.Equals(true))
            //        {
            //            AffectedCity.SupportPersonnelNeeded = "MILITARY";
            //        }
            //        if (chkbxUpdateVolunteer.Checked.Equals(true))
            //        {
            //            AffectedCity.SupportPersonnelNeeded = "VOLUNTEER";
            //        }
            //        if (chkbxUpdateMedical.Checked.Equals(true) && chkbxUpdateMilitary.Equals(true))
            //        {
            //            AffectedCity.SupportPersonnelNeeded = "MEDICAL AND MILITARY";
            //        }
            //        if (chkbxUpdateMedical.Checked.Equals(true) && chkbxUpdateVolunteer.Equals(true))
            //        {
            //            AffectedCity.SupportPersonnelNeeded = "MEDICAL AND VOLUNTEER";
            //        }
            //        if (chkbxUpdateMilitary.Checked.Equals(true) && chkbxUpdateVolunteer.Equals(true))
            //        {
            //            AffectedCity.SupportPersonnelNeeded = "MILITARY AND VOLUNTEER";
            //        }
            //        if (chkbxUpdateMedical.Checked.Equals(true) && chkbxUpdateMilitary.Checked.Equals(true) && chkbxUpdateVolunteer.Checked.Equals(true))
            //        {
            //            AffectedCity.SupportPersonnelNeeded = "MEDICAL AND MILITARY AND VOLUNTEER";
            //        }

            //    }
            //}

            AffectedCityControl.updateAffectedCity(tbxUpdateCityId, tbxUpdateNameOfCity, tbxUpdateNoOfPopulation, tbxUpdateDescOfDmg, radioBtnUpdateLow, radioBtnUpdateMedium, radioBtnUpdateHigh, chkbxUpdateMedical, chkbxUpdateMilitary, chkbxUpdateVolunteer);
            MessageBox.Show("City Updated Successful!");
        }

        private void radioBtnDelMulti_CheckedChanged(object sender, EventArgs e)
        {
            if (radioBtnDelMulti.Checked.Equals(true))
            {
                pnlDeleteMultiCity.Show();
                pnlDeleteSingleCity.Hide();
                tbxSearchDGVDelAffectedCity.Focus();
                AffectedCityControl.DGVDelAffectedCity(DGVDelAffectedCity);

                ////1. clear the datagrid view first
                ////DGVDelAffectedCity.Rows.Clear();
                //DGVDelAffectedCity.DataSource = null;
                //DGV tbxDeleteAffectedCitySearc tbxDeleteAffectedCitySearc.Refresh();


                //if (AllFormClass.AffectedCity.Count > 0)
                //{
                //    DGVDelAffectedCity.DataSource = AllFormClass.AffectedCity;
                //    DGVDelAffectedCity.Refresh();
                //}
                

                ////2. to populate the datagridview from the arraylist of affected city
                //foreach (AffectedCity ac in AllFormClass.AffectedCity)
                //{
                //    // add row to dgv
                //    DGVDelAffectedCity.Rows.Add(ac.NameOfCity, ac.NoOfPopulation, ac.LvlOfDisaster, ac.SupportPersonnelNeeded, ac.ShortDescOfDmg);
                //}
            }
        }
        //AffectedCity ac;

        private void btnDelMultiCity_Click(object sender, EventArgs e)
        {
            ArrayList integer = new ArrayList();
            foreach (DataGridViewRow row in DGVDelAffectedCity.SelectedRows)
            {
                integer.Add(row.Cells[0].Value);
            }

            //for (int i = AllFormClass.AffectedCity.Count - 1; i >= 0; i--)
            //{
            //    AffectedCity ac = (AffectedCity)AllFormClass.AffectedCity[i];

            //    for (int j = 0; j < integer.Count; j++)
            //    {
            //        if (ac.CityID1 == Convert.ToInt32(integer[j]))
            //        {
            //            AllFormClass.AffectedCity.RemoveAt(i);
            //        }
            //    }
            //}

            //DGVDelAffectedCity.DataSource = null;
            //DGVDelAffectedCity.Refresh();

            //DGVDelAffectedCity.DataSource = AllFormClass.AffectedCity;
            //DGVDelAffectedCity.Refresh();
            AffectedCityControl.deleteMultiAffectedCity(integer, DGVDelAffectedCity);
        }

        private void pnlDeleteYears_Paint(object sender, PaintEventArgs e)
        {

        }

        private void radioBtnDelSingle_CheckedChanged(object sender, EventArgs e)
        {
            if (radioBtnDelSingle.Checked.Equals(true))
            {
                pnlDeleteMultiCity.Hide();
                pnlDeleteSingleCity.Show();
                searchDeleteAffectedCityResult.Hide();

                tbxDeleteAffectedCitySearch.Focus();
                //DGVDelAffectedCity.Rows.Clear();

            }
        }

        //private void tbxNameOfCity_KeyUp(object sender, KeyEventArgs e)
        //{
        //    for (int i = 0; i < AllFormClass.AffectedCity.Count; i++)
        //    {
        //        AffectedCity a = (AffectedCity)AllFormClass.AffectedCity[i];
        //        if (tbxNameOfCity.Text.Trim() == a.NameOfCity.ToString())
        //        {
        //            this.btnAddCity.Enabled = false;
        //        }
        //        else
        //        {
        //            this.btnAddCity.Enabled = true;
        //        }
        //    }
        //}
       
        private void tbxNameOfCity_Leave(object sender, EventArgs e)
        {
            AffectedCityControl.checkExist(tbxNameOfCity);
            //notSimilarName = tbxNameOfCity.Text != "";
            if (AllFormClass.AffectedCity.Count > 0)
            {
                for (int i = 0; i < AllFormClass.AffectedCity.Count; i++)
                {
                    AffectedCity a = (AffectedCity)AllFormClass.AffectedCity[i];
                    if (tbxNameOfCity.Text.Trim() == a.NameOfCity.ToString())
                    {
                        notSimilarName = false;
                        CityAlrExisitError.SetError(tbxNameOfCity, "City already exist! ");
                        break;

                    }
                    else if (tbxNameOfCity.Text.Trim() != a.NameOfCity.ToString())
                    {
                        notSimilarName = true;
                        CityAlrExisitError.Clear();
                        //break;
                    }
                }
            }
            else
            {
                notSimilarName = true;
            }
            

            if (notSimilarName && nameofcity && noofpop && radiocheck && (military || volunteer || medical))
            {
                this.btnAddCity.Enabled = true;
            }
            else
            {
                this.btnAddCity.Enabled = false;
            }
        }

        private void tbxSearchAssignAffectedCity_TextChanged(object sender, EventArgs e)
        {
            //char firstChar = '0';
            //this.lbxAssignSupportPersonnelToCityResult2.Items.Clear();

            //if (tbxSearchAssignAffectedCity.Text != String.Empty)
            //{
            //    if (firstChar != tbxSearchAssignAffectedCity.Text[0])
            //    {
            //        firstChar = tbxSearchAssignAffectedCity.Text[0];

            //        for (int i = 0; i < AllFormClass.AffectedCity.Count; i++)
            //        {
            //            AffectedCity a = (AffectedCity)AllFormClass.AffectedCity[i];
            //            String searchItem = a.NameOfCity.ToString();
            //            if (searchItem[0] == firstChar)
            //            {
            //                lbxAssignSupportPersonnelToCityResult2.DisplayMember = "FirstName";
            //                lbxAssignSupportPersonnelToCityResult2.Items.Add(a.NameOfCity);

            //            }
            //        }
            //    }
            //}
            lbxAssignSupportPersonnelToCityResult2.Show();
            this.lbxAssignSupportPersonnelToCityResult2.Items.Clear();
            if (tbxSearchAssignAffectedCity.Text != String.Empty)
            {
                for (int i = 0; i < AllFormClass.AffectedCity.Count; i++)
                {
                    AffectedCity a = (AffectedCity)AllFormClass.AffectedCity[i];
                    String searchItem = a.NameOfCity.ToString();
                    if (searchItem.Contains(tbxSearchAssignAffectedCity.Text))
                    {
                        lbxAssignSupportPersonnelToCityResult2.DisplayMember = "NameOfCity";
                        lbxAssignSupportPersonnelToCityResult2.Items.Add(a.NameOfCity);
                    }
                }
            }
        }

        private void lbxAssignSupportPersonnelToCityResult2_SelectedIndexChanged(object sender, EventArgs e)
        {
            pnlAssignSupportPersonnelDetails2.Show();
            try
            {
                string selectedtitle = lbxAssignSupportPersonnelToCityResult2.SelectedItem.ToString();
                foreach (AffectedCity AffectedCity in AllFormClass.AffectedCity)
                {
                    if (AffectedCity.NameOfCity == selectedtitle)
                    {
                        lblAssignSupportPersonnelCityID.Text = Convert.ToString(AffectedCity.CityID1);
                        lblAssignSupportPersonnelCityName.Text = AffectedCity.NameOfCity;
                        lblAssignSupportPersonnelCityPop.Text = AffectedCity.NoOfPopulation;
                        lblAssignSupportPersonnelCityShortDesc.Text = AffectedCity.ShortDescOfDmg;
                        lblAssignSupportPersonnelCityLvlOfDisaster.Text = Convert.ToString(AffectedCity.LvlOfDisaster);
                        lblAssignSupportPersonnelCitySupportPersonnelRequired.Text = Convert.ToString(AffectedCity.SupportPersonnelNeeded);
                    }
                }
            }
            catch (NullReferenceException nre)
            {
                return;
            }

        }

        private void btnSelectCityToBeAssigned_Click(object sender, EventArgs e)
        {
            pnlAssignSupportPersonnelDetails2.Hide();
            pnlDisplayListOfSupportPersonnelToBeAssigned.Show();

            //for (int i = 0; i < AllFormClass.AssignMedical.Count; i++)
            //{
            //    AllFormClass.AssignMedical.Remove(i);
            //}
                   AllFormClass.AssignMedical.Clear();
                   AllFormClass.AssignMilitary.Clear();
                   AllFormClass.AssignVolunteer.Clear();
                   AllFormClass.AssignMedicalNMilitary.Clear();
                   AllFormClass.AssignMedicalNVolunteer.Clear();
                   AllFormClass.AssignMedicalNMilitary.Clear();
                   AllFormClass.AssignMedicalNMilitaryNVolunteer.Clear();

            //string selectedtitle = lbxAssignSupportPersonnelToCityResult2.SelectedItem.ToString();
            //for (int i = 0; i < AllFormClass.AffectedCity.Count; i++)
            //{
            //    AffectedCity a = (AffectedCity)AllFormClass.AffectedCity[i];
            //    if (a.SupportPersonnelNeeded == )
            //}

            string supportpersonnelrequired = lblAssignSupportPersonnelCitySupportPersonnelRequired.Text;
            DGVListOfSupportPersonnelToBeAssigned.DataSource = null;
            DGVListOfSupportPersonnelToBeAssigned.Refresh();
            if (supportpersonnelrequired == "MEDICAL")
            {
                DGVListOfSupportPersonnelToBeAssigned.DataSource = null;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();
                for (int i = 0; i < AllFormClass.SupportPersonnels.Count; i++)
                {
                    SupportPersonnels s = (SupportPersonnels)AllFormClass.SupportPersonnels[i];

                    if (s.TypeOfPersonnel == "MEDICAL" && s.CityAssigned1 == "NILL")
                    {
                        AllFormClass.AssignMedical.Add(s);
                        //DGVListOfSupportPersonnelToBeAssigned.DataSource = AllFormClass.test1;
                        //DGVListOfSupportPersonnelToBeAssigned.Refresh();
                    }
                    
                }
                DGVListOfSupportPersonnelToBeAssigned.DataSource = AllFormClass.AssignMedical;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();
           }


            else if (supportpersonnelrequired == "MILITARY")
            {
                DGVListOfSupportPersonnelToBeAssigned.DataSource = null;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();
                for (int i = 0; i < AllFormClass.SupportPersonnels.Count; i++)
                {
                    SupportPersonnels s = (SupportPersonnels)AllFormClass.SupportPersonnels[i];

                    if (s.TypeOfPersonnel == "MILITARY" && s.CityAssigned1 == "NILL")
                    {
                        AllFormClass.AssignMilitary.Add(s);
                        //DGVListOfSupportPersonnelToBeAssigned.DataSource = AllFormClass.test1;
                        //DGVListOfSupportPersonnelToBeAssigned.Refresh();
                    }

                }
                DGVListOfSupportPersonnelToBeAssigned.DataSource = AllFormClass.AssignMilitary;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();
            }

            else if (supportpersonnelrequired == "VOLUNTEER")
            {
                DGVListOfSupportPersonnelToBeAssigned.DataSource = null;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();
                for (int i = 0; i < AllFormClass.SupportPersonnels.Count; i++)
                {
                    SupportPersonnels s = (SupportPersonnels)AllFormClass.SupportPersonnels[i];

                    if (s.TypeOfPersonnel == "VOLUNTEER" && s.CityAssigned1 == "NILL")
                    {
                        AllFormClass.AssignVolunteer.Add(s);
                        //DGVListOfSupportPersonnelToBeAssigned.DataSource = AllFormClass.test1;
                        //DGVListOfSupportPersonnelToBeAssigned.Refresh();
                    }

                }
                DGVListOfSupportPersonnelToBeAssigned.DataSource = AllFormClass.AssignVolunteer;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();
            }

            else if (supportpersonnelrequired == "MEDICAL AND MILITARY")
            {
                DGVListOfSupportPersonnelToBeAssigned.DataSource = null;
                DGVDelAffectedCity.Refresh();
                for (int i = 0; i < AllFormClass.SupportPersonnels.Count; i++)
                {
                    SupportPersonnels s = (SupportPersonnels)AllFormClass.SupportPersonnels[i];

                    if ((s.TypeOfPersonnel == "MEDICAL" || s.TypeOfPersonnel == "MILITARY") && s.CityAssigned1 == "NILL")
                    {
                        AllFormClass.AssignMedicalNMilitary.Add(s);
                    }
                    
                }
                DGVListOfSupportPersonnelToBeAssigned.DataSource = AllFormClass.AssignMedicalNMilitary;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();
            }

            else if (supportpersonnelrequired == "MEDICAL AND VOLUNTEER")
            {
                DGVListOfSupportPersonnelToBeAssigned.DataSource = null;
                DGVDelAffectedCity.Refresh();
                for (int i = 0; i < AllFormClass.SupportPersonnels.Count; i++)
                {
                    SupportPersonnels s = (SupportPersonnels)AllFormClass.SupportPersonnels[i];

                    if ((s.TypeOfPersonnel == "MEDICAL" || s.TypeOfPersonnel == "VOLUNTEER") && s.CityAssigned1 == "NILL")
                    {
                        AllFormClass.AssignMedicalNVolunteer.Add(s);
                    }

                }
                DGVListOfSupportPersonnelToBeAssigned.DataSource = AllFormClass.AssignMedicalNVolunteer;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();
            }

            else if (supportpersonnelrequired == "MILITARY AND VOLUNTEER")
            {
                DGVListOfSupportPersonnelToBeAssigned.DataSource = null;
                DGVDelAffectedCity.Refresh();
                for (int i = 0; i < AllFormClass.SupportPersonnels.Count; i++)
                {
                    SupportPersonnels s = (SupportPersonnels)AllFormClass.SupportPersonnels[i];

                    if ((s.TypeOfPersonnel == "MILITARY" || s.TypeOfPersonnel == "VOLUNTEER") && s.CityAssigned1 == "NILL")
                    {
                        AllFormClass.AssignMilitaryNVolunteer.Add(s);
                    }

                }
                DGVListOfSupportPersonnelToBeAssigned.DataSource = AllFormClass.AssignMilitaryNVolunteer;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();
            }

            else if (supportpersonnelrequired == "MEDICAL AND MILITARY AND VOLUNTEER")
            {
                DGVListOfSupportPersonnelToBeAssigned.DataSource = null;
                DGVDelAffectedCity.Refresh();
                for (int i = 0; i < AllFormClass.SupportPersonnels.Count; i++)
                {
                    SupportPersonnels s = (SupportPersonnels)AllFormClass.SupportPersonnels[i];

                    if ((s.TypeOfPersonnel == "MILITARY" || s.TypeOfPersonnel == "VOLUNTEER" || s.TypeOfPersonnel == "MEDICAL") && s.CityAssigned1 == "NILL")
                    {
                        AllFormClass.AssignMedicalNMilitaryNVolunteer.Add(s);
                    }

                }
                DGVListOfSupportPersonnelToBeAssigned.DataSource = AllFormClass.AssignMedicalNMilitaryNVolunteer;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();
            }
            
        }

        private void tbxtest_TextChanged(object sender, EventArgs e)
        {

            if (tbxSearchDGVDelAffectedCity.Text != String.Empty)
            {
                String search = tbxSearchDGVDelAffectedCity.Text;
                foreach (DataGridViewRow i in DGVDelAffectedCity.Rows)
                {
                    i.Selected = false;
                    String searchItem = i.Cells[1].Value.ToString();
                    if (searchItem.Contains(tbxSearchDGVDelAffectedCity.Text))
                    {
                        i.Selected = true;
                        //break;
                    }
                    else
                    {
                        i.Selected = false;
                        // break;
                    }
                }
            }
            else
            {
                foreach (DataGridViewRow i in DGVDelAffectedCity.Rows)
                {
                    i.Selected = false;
                }

            }
            tbxSearchAssignSP.Focus();
        }

        private void btnSelectPersonnelToBeAssigned_Click(object sender, EventArgs e)
        {
            //string name = "";
            //string selectedtitle = lbxAssignSupportPersonnelToCityResult2.SelectedItem.ToString();
            //foreach (AffectedCity AffectedCity in AllFormClass.AffectedCity)
            //{
            //    if (AffectedCity.NameOfCity == selectedtitle)
            //    {
            //         name = AffectedCity.NameOfCity;
            //    }
            //}
            //ArrayList integer = new ArrayList();
            //foreach (DataGridViewRow row in DGVListOfSupportPersonnelToBeAssigned.SelectedRows)
            //{
            //    for (int i = 0; i < AllFormClass.SupportPersonnels.Count; i++)
            //    {
            //        SupportPersonnels sp = (SupportPersonnels)AllFormClass.SupportPersonnels[i];
            //        sp.CityAssigned1 = name;
            //    }

            //}

            // medical
            string name = "";
            ArrayList integer = new ArrayList();
            string supportpersonnelrequired = lblAssignSupportPersonnelCitySupportPersonnelRequired.Text;
            if (supportpersonnelrequired == "MEDICAL")
            {
                name = lblAssignSupportPersonnelCityName.Text;

                foreach (DataGridViewRow row in DGVListOfSupportPersonnelToBeAssigned.SelectedRows)
                {
                    integer.Add(row.Cells[5].Value);
                }
                
                for (int i = 0; i < AllFormClass.SupportPersonnels.Count; i++)
                {
                    SupportPersonnels sp = (SupportPersonnels)AllFormClass.SupportPersonnels[i];
                    for (int j = 0; j < integer.Count; j++)
                    {
                        if (sp.personnelID == Convert.ToInt32(integer[j]))
                        {
                            sp.CityAssigned1 = name;
                            if (sp.TypeOfPersonnel == "MEDICAL" && sp.CityAssigned1 == "NILL")
                            {
                                AllFormClass.AssignMedical.Add(i);
                            }
                        }
                    }
                }
                DGVListOfSupportPersonnelToBeAssigned.DataSource = null;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();
                DGVListOfSupportPersonnelToBeAssigned.DataSource = AllFormClass.AssignMedical;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();

                tbxSearchAssignAffectedCity.Clear();
                lbxAssignSupportPersonnelToCityResult2.ClearSelected();
                pnlAssignSupportPersonnelDetails2.Hide();
                pnlDisplayListOfSupportPersonnelToBeAssigned.Hide();
            }

            //military
            else if (supportpersonnelrequired == "MILITARY")
            {
                name = lblAssignSupportPersonnelCityName.Text;

                foreach (DataGridViewRow row in DGVListOfSupportPersonnelToBeAssigned.SelectedRows)
                {
                    integer.Add(row.Cells[5].Value);
                }
                // AllFormClass.AssignMedical.Clear();
                for (int i = 0; i < AllFormClass.SupportPersonnels.Count; i++)
                {
                    SupportPersonnels sp = (SupportPersonnels)AllFormClass.SupportPersonnels[i];
                    for (int j = 0; j < integer.Count; j++)
                    {
                        if (sp.personnelID == Convert.ToInt32(integer[j]))
                        {
                            sp.CityAssigned1 = name;
                            if (sp.TypeOfPersonnel == "MILITARY" && sp.CityAssigned1 == "NILL")
                            {
                                AllFormClass.AssignMilitary.Add(i);
                            }
                        }
                    }
                }
                DGVListOfSupportPersonnelToBeAssigned.DataSource = null;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();
                DGVListOfSupportPersonnelToBeAssigned.DataSource = AllFormClass.AssignMilitary;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();

                tbxSearchAssignAffectedCity.Clear();
                lbxAssignSupportPersonnelToCityResult2.ClearSelected();
                pnlAssignSupportPersonnelDetails2.Hide();
                pnlDisplayListOfSupportPersonnelToBeAssigned.Hide();
            }

            //volunteer
            else if (supportpersonnelrequired == "VOLUNTEER")
            {
                name = lblAssignSupportPersonnelCityName.Text;
                foreach (DataGridViewRow row in DGVListOfSupportPersonnelToBeAssigned.SelectedRows)
                {
                    integer.Add(row.Cells[5].Value);
                }
                // AllFormClass.AssignMedical.Clear();
                for (int i = 0; i < AllFormClass.SupportPersonnels.Count; i++)
                {
                    SupportPersonnels sp = (SupportPersonnels)AllFormClass.SupportPersonnels[i];
                    for (int j = 0; j < integer.Count; j++)
                    {
                        if (sp.personnelID == Convert.ToInt32(integer[j]))
                        {
                            sp.CityAssigned1 = name;
                            if (sp.TypeOfPersonnel == "VOLUNTEER" && sp.CityAssigned1 == "NILL")
                            {
                                AllFormClass.AssignVolunteer.Add(i);
                            }
                        }
                    }
                }

                DGVListOfSupportPersonnelToBeAssigned.DataSource = null;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();
                DGVListOfSupportPersonnelToBeAssigned.DataSource = AllFormClass.AssignVolunteer;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();

                tbxSearchAssignAffectedCity.Clear();
                lbxAssignSupportPersonnelToCityResult2.ClearSelected();
                pnlAssignSupportPersonnelDetails2.Hide();
                pnlDisplayListOfSupportPersonnelToBeAssigned.Hide();
            }

            //MEDICAL AND MILITARY
            else if (supportpersonnelrequired == "MEDICAL AND MILITARY")
            {
                name = lblAssignSupportPersonnelCityName.Text;
                foreach (DataGridViewRow row in DGVListOfSupportPersonnelToBeAssigned.SelectedRows)
                {
                    integer.Add(row.Cells[5].Value);
                }

                // AllFormClass.AssignMedical.Clear();

                for (int i = 0; i < AllFormClass.SupportPersonnels.Count; i++)
                {
                    SupportPersonnels sp = (SupportPersonnels)AllFormClass.SupportPersonnels[i];
                    for (int j = 0; j < integer.Count; j++)
                    {
                        if (sp.personnelID == Convert.ToInt32(integer[j]))
                        {
                            sp.CityAssigned1 = name;
                            if ((sp.TypeOfPersonnel == "MEDICAL" || sp.TypeOfPersonnel == "MILITARY") && sp.CityAssigned1 == "NILL")
                            {
                                AllFormClass.AssignMedicalNMilitary.Add(i);
                            }

                        }
                    }
                }

                DGVListOfSupportPersonnelToBeAssigned.DataSource = null;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();
                DGVListOfSupportPersonnelToBeAssigned.DataSource = AllFormClass.AssignMedicalNMilitary;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();

                tbxSearchAssignAffectedCity.Clear();
                lbxAssignSupportPersonnelToCityResult2.ClearSelected();
                pnlAssignSupportPersonnelDetails2.Hide();
                pnlDisplayListOfSupportPersonnelToBeAssigned.Hide();
            }

            //medical and volunteer
            else if (supportpersonnelrequired == "MEDICAL AND VOLUNTEER")
            {
                name = lblAssignSupportPersonnelCityName.Text;

                foreach (DataGridViewRow row in DGVListOfSupportPersonnelToBeAssigned.SelectedRows)
                {
                    integer.Add(row.Cells[5].Value);
                }

                // AllFormClass.AssignMedical.Clear();

                for (int i = 0; i < AllFormClass.SupportPersonnels.Count; i++)
                {
                    SupportPersonnels sp = (SupportPersonnels)AllFormClass.SupportPersonnels[i];
                    for (int j = 0; j < integer.Count; j++)
                    {
                        if (sp.personnelID == Convert.ToInt32(integer[j]))
                        {
                            sp.CityAssigned1 = name;
                            if ((sp.TypeOfPersonnel == "MEDICAL" || sp.TypeOfPersonnel == "VOLUNTEER") && sp.CityAssigned1 == "NILL")
                            {
                                AllFormClass.AssignMedicalNVolunteer.Add(i);
                            }

                        }
                    }
                }

                DGVListOfSupportPersonnelToBeAssigned.DataSource = null;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();
                DGVListOfSupportPersonnelToBeAssigned.DataSource = AllFormClass.AssignMedicalNVolunteer;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();

                tbxSearchAssignAffectedCity.Clear();
                lbxAssignSupportPersonnelToCityResult2.ClearSelected();
                pnlAssignSupportPersonnelDetails2.Hide();
                pnlDisplayListOfSupportPersonnelToBeAssigned.Hide();
            }

            //military and volunteer
            else if (supportpersonnelrequired == "MILITARY AND VOLUNTEER")
            {
                name = lblAssignSupportPersonnelCityName.Text;

                foreach (DataGridViewRow row in DGVListOfSupportPersonnelToBeAssigned.SelectedRows)
                {
                    integer.Add(row.Cells[5].Value);
                }

                // AllFormClass.AssignMedical.Clear();

                for (int i = 0; i < AllFormClass.SupportPersonnels.Count; i++)
                {
                    SupportPersonnels sp = (SupportPersonnels)AllFormClass.SupportPersonnels[i];
                    for (int j = 0; j < integer.Count; j++)
                    {
                        if (sp.personnelID == Convert.ToInt32(integer[j]))
                        {
                            sp.CityAssigned1 = name;
                            if ((sp.TypeOfPersonnel == "MILITARY" || sp.TypeOfPersonnel == "VOLUNTEER") && sp.CityAssigned1 == "NILL")
                            {
                                AllFormClass.AssignMilitaryNVolunteer.Add(i);
                            }

                        }
                    }
                }

                DGVListOfSupportPersonnelToBeAssigned.DataSource = null;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();
                DGVListOfSupportPersonnelToBeAssigned.DataSource = AllFormClass.AssignMilitaryNVolunteer;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();

                tbxSearchAssignAffectedCity.Clear();
                lbxAssignSupportPersonnelToCityResult2.ClearSelected();
                pnlAssignSupportPersonnelDetails2.Hide();
                pnlDisplayListOfSupportPersonnelToBeAssigned.Hide();
            }

            //MEDICAL AND MILITARY AND VOLUNTEER
            else if (supportpersonnelrequired == "MEDICAL AND MILITARY AND VOLUNTEER")
            {
                name = lblAssignSupportPersonnelCityName.Text;

                foreach (DataGridViewRow row in DGVListOfSupportPersonnelToBeAssigned.SelectedRows)
                {
                    integer.Add(row.Cells[5].Value);
                }

                // AllFormClass.AssignMedical.Clear();

                for (int i = 0; i < AllFormClass.SupportPersonnels.Count; i++)
                {
                    SupportPersonnels sp = (SupportPersonnels)AllFormClass.SupportPersonnels[i];
                    for (int j = 0; j < integer.Count; j++)
                    {
                        if (sp.personnelID == Convert.ToInt32(integer[j]))
                        {
                            sp.CityAssigned1 = name;
                            if ((sp.TypeOfPersonnel == "MEDICAL" || sp.TypeOfPersonnel == "MILITARY" || sp.TypeOfPersonnel == "VOLUNTEER") && sp.CityAssigned1 == "NILL")
                            {
                                AllFormClass.AssignMedicalNMilitaryNVolunteer.Add(i);
                            }

                        }
                    }
                }

                DGVListOfSupportPersonnelToBeAssigned.DataSource = null;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();
                DGVListOfSupportPersonnelToBeAssigned.DataSource = AllFormClass.AssignMedicalNMilitaryNVolunteer;
                DGVListOfSupportPersonnelToBeAssigned.Refresh();

                tbxSearchAssignAffectedCity.Clear();
                lbxAssignSupportPersonnelToCityResult2.ClearSelected();
                pnlAssignSupportPersonnelDetails2.Hide();
                pnlDisplayListOfSupportPersonnelToBeAssigned.Hide();
            }

            MessageBox.Show("Support Personnel(s) Assigned Successfully");

        }

        private void btnUpdateReset_Click(object sender, EventArgs e)
        {
            tbxUpdateNameOfCity.Clear();
            tbxUpdateNoOfPopulation.Clear();
            tbxUpdateDescOfDmg.Clear();
            radioBtnUpdateLow.Checked = false;
            radioBtnUpdateMedium.Checked = false;
            radioBtnUpdateHigh.Checked = false;
            chkbxUpdateMedical.Checked = false;
            chkbxUpdateMilitary.Checked = false;
            chkbxUpdateVolunteer.Checked = false;
        }

        private void tbxUpdateNameOfCity_KeyDown(object sender, KeyEventArgs e)
        {
            // Initialize the flag to false.
            nonLetterEntered = false;

            // Determine whether the keystroke is a number from the top of the keyboard.
            if (e.KeyCode < Keys.A || e.KeyCode > Keys.Z)
            {
                //// Determine whether the keystroke is a number from the keypad.
                //if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
                //{
                if (e.KeyCode != Keys.Space)
                {
                    // Determine whether the keystroke is a backspace.
                    if (e.KeyCode != Keys.Back)
                    {
                        // A non-numerical keystroke was pressed.
                        // Set the flag to true and evaluate in KeyPress event.
                        nonLetterEntered = true;
                    }
                }

                //}
            }
            //If shift key was pressed, it's not a number.
            if (Control.ModifierKeys == Keys.Shift)
            {
                nonLetterEntered = true;
            }
        }

        private void tbxUpdateNameOfCity_KeyPress(object sender, KeyPressEventArgs e)
        {
            // Check for the flag being set in the KeyDown event.
            if (nonLetterEntered == true)
            {
                // Stop the character from being entered into the control since it is non-numerical.
                e.Handled = true;
            }
        }

        private void tbxUpdateNoOfPopulation_KeyDown(object sender, KeyEventArgs e)
        {
            // Initialize the flag to false.
            nonNumberEntered = false;

            // Determine whether the keystroke is a number from the top of the keyboard.
            if (e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9)
            {
                // Determine whether the keystroke is a number from the keypad.
                if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
                {
                    // Determine whether the keystroke is a backspace.
                    if (e.KeyCode != Keys.Back)
                    {
                        // A non-numerical keystroke was pressed.
                        // Set the flag to true and evaluate in KeyPress event.
                        nonNumberEntered = true;
                    }
                }
            }
            //If shift key was pressed, it's not a number.
            if (Control.ModifierKeys == Keys.Shift)
            {
                nonNumberEntered = true;
            }
        }

        private void tbxUpdateNoOfPopulation_KeyPress(object sender, KeyPressEventArgs e)
        {
            // Check for the flag being set in the KeyDown event.
            if (nonNumberEntered == true)
            {
                // Stop the character from being entered into the control since it is non-numerical.
                e.Handled = true;
            }
        }

        private void tbxUpdateNameOfCity_TextChanged(object sender, EventArgs e)
        {
            updateNameOfCity = tbxUpdateNameOfCity.Text != "";
            if (updateNameOfCity && updateNoOfPop && updateRadioCheck && (updateMedical || updateMilitary || updateVolunteer))
            {
                this.btnUpdateCity.Enabled = true;
            }
            else
            {
                this.btnUpdateCity.Enabled = false;
            }

        }

        private void tbxUpdateNoOfPopulation_TextChanged(object sender, EventArgs e)
        {
            updateNoOfPop = tbxUpdateNoOfPopulation.Text != "";
            if (updateNameOfCity && updateNoOfPop && updateRadioCheck && (updateMedical || updateMilitary || updateVolunteer))
            {
                this.btnUpdateCity.Enabled = true;
            }
            else
            {
                this.btnUpdateCity.Enabled = false;
            }
        }

        private void radioBtnUpdateLow_CheckedChanged(object sender, EventArgs e)
        {
            updateRadioCheck = true;
            if (updateNameOfCity && updateNoOfPop && updateRadioCheck && (updateMedical || updateMilitary || updateVolunteer))
            {
                this.btnUpdateCity.Enabled = true;
            }
            else
            {
                this.btnUpdateCity.Enabled = false;
            }
        }

        private void radioBtnUpdateMedium_CheckedChanged(object sender, EventArgs e)
        {
            updateRadioCheck = true;
            if (updateNameOfCity && updateNoOfPop && updateRadioCheck && (updateMedical || updateMilitary || updateVolunteer))
            {
                this.btnUpdateCity.Enabled = true;
            }
            else
            {
                this.btnUpdateCity.Enabled = false;
            }
        }

        private void radioBtnUpdateHigh_CheckedChanged(object sender, EventArgs e)
        {
            updateRadioCheck = true;
            if (updateNameOfCity && updateNoOfPop && updateRadioCheck && (updateMedical || updateMilitary || updateVolunteer))
            {
                this.btnUpdateCity.Enabled = true;
            }
            else
            {
                this.btnUpdateCity.Enabled = false;
            }
        }

        private void chkbxUpdateMedical_CheckedChanged(object sender, EventArgs e)
        {
            updateMedical = chkbxUpdateMedical.Checked;
            if (updateNameOfCity && updateNoOfPop && updateRadioCheck && (updateMedical || updateMilitary || updateVolunteer))
            {
                this.btnUpdateCity.Enabled = true;
            }
            else
            {
                this.btnUpdateCity.Enabled = false;
            }

        }

        private void chkbxUpdateMilitary_CheckedChanged(object sender, EventArgs e)
        {
            updateMilitary = chkbxUpdateMilitary.Checked;
            if (updateNameOfCity && updateNoOfPop && updateRadioCheck && (updateMedical || updateMilitary || updateVolunteer))
            {
                this.btnUpdateCity.Enabled = true;
            }
            else
            {
                this.btnUpdateCity.Enabled = false;
            }
        }

        private void chkbxUpdateVolunteer_CheckedChanged(object sender, EventArgs e)
        {
            updateVolunteer = chkbxUpdateVolunteer.Checked;
            if (updateNameOfCity && updateNoOfPop && updateRadioCheck && (updateMedical || updateMilitary || updateVolunteer))
            {
                this.btnUpdateCity.Enabled = true;
            }
            else
            {
                this.btnUpdateCity.Enabled = false;
            }
        }

        private void DGVListOfSupportPersonnelToBeAssigned_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        //private void tbxUpdateNameOfCity_Leave(object sender, EventArgs e)
        //{
        //    if (AllFormClass.AffectedCity.Count > 0)
        //    {
        //        for (int i = 0; i < AllFormClass.AffectedCity.Count; i++)
        //        {
        //            AffectedCity a = (AffectedCity)AllFormClass.AffectedCity[i];
        //            if (tbxUpdateNameOfCity.Text.Trim() == a.NameOfCity.ToString())
        //            {
        //                updateNotSimilarName = false;
        //                updateCityAlrExisitError.SetError(tbxUpdateNameOfCity, "City already exist!");
        //                break;
        //            }
        //            else if (tbxUpdateNameOfCity.Text.Trim() != a.NameOfCity.ToString())
        //            {
        //                updateNotSimilarName = true;
        //                updateCityAlrExisitError.Clear();

        //            }
        //        }
        //    }
        //    else
        //    {
        //        updateNotSimilarName = true;
        //    }

        //    if (updateNotSimilarName && updateNameOfCity && updateNoOfPop && updateRadioCheck && (updateMedical || updateMilitary || updateVolunteer))
        //    {
        //        this.btnUpdateCity.Enabled = true;
        //    }
        //    else
        //    {
        //        this.btnUpdateCity.Enabled = false;
        //    }
        //}




        //copyhere===============================================================================================


        private void timer1_Tick_1(object sender, EventArgs e)
        {
            this.lblTime.Text = DateTime.Now.ToString();
        }

        private void timer2_Tick_1(object sender, EventArgs e)
        {
            foreach (user u in AllFormClass.User)
            {
                if (u.Name == u.Name)
                {
                    this.lblWelcome.Text = "Welcome, " + u.Name;
                }
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            DialogResult dr = MessageBox.Show("Are you sure you want to logout?",
                              "Warning",
                              MessageBoxButtons.YesNo,
                              MessageBoxIcon.Exclamation);

            if (dr == DialogResult.Yes)
            {
                AllFormClass.lp.Show();
                this.Hide();
            }
            else if (dr == DialogResult.No)
            {

            }
        }

        private void tbxSearchAssignSP_TextChanged(object sender, EventArgs e)
        {
            if (tbxSearchAssignSP.Text != String.Empty)
            {
                String search = tbxSearchAssignSP.Text;
                foreach (DataGridViewRow i in DGVListOfSupportPersonnelToBeAssigned.Rows)
                {
                    i.Selected = false;
                    String searchItem = i.Cells[0].Value.ToString();
                    if (searchItem.Contains(tbxSearchAssignSP.Text))
                    {
                        i.Selected = true;
                        //break;
                    }
                    else
                    {
                        i.Selected = false;
                        // break;
                    }
                }
            }
            else
            {
                foreach (DataGridViewRow i in DGVListOfSupportPersonnelToBeAssigned.Rows)
                {
                    i.Selected = false;
                }

            }
        }

        SupportPersonnels sp;
        
        private void btnDelSpfromAC_Click(object sender, EventArgs e)
        {
            
            foreach (DataGridViewRow row in DGVDelSPfromAC.SelectedRows)
            {
                int index = DGVDelSPfromAC.CurrentCell.RowIndex;
                sp = (SupportPersonnels)AllFormClass.SupportPersonnels[index];
                
                sp.CityAssigned1 = "NILL";

                for (int i = 0; i < AllFormClass.DelSPfromAC.Count; i++)
                {
                    if (i == index)
                    {
                        AllFormClass.DelSPfromAC.Remove(i);
                    }
                }

            }
            DGVDelSPfromAC.DataSource = null;
            DGVDelSPfromAC.Refresh();
            DGVDelSPfromAC.DataSource = AllFormClass.DelSPfromAC;
            DGVDelSPfromAC.Refresh();
            
        }

        private void lblViewSupportPersonnel_LinkClicked_2(object sender, LinkLabelLinkClickedEventArgs e)
        {
            pnlViewSupportPersonnel.Show();
            pnlAddNewAffectedCity.Hide();
            pnlEmpty.Hide();
            pnlAssignSupportPersonnelDetails1.Hide();
            pnlAssignSupportPersonnelDetails2.Hide();
            pnlAssignSupportToAffectedCity1.Hide();
            pnlAssignSupportToAffectedCity2.Hide();
            pnlDeleteYears.Hide();
            pnlDeleteAffectedCityDetails.Hide();
            //  pnlDeleteSupportPersonnelDetails.Hide();
            pnlDeleteSupportPersonnelFromAffectedCity1.Hide();
            pnlUpdateAffectedCity.Hide();
            pnlUpdateAffectedCityDetails.Hide();
            pnlUpdateSupportPersonnel.Hide();
            pnlUpdateSupportPersonnelDetails.Hide();
            pnlViewCityProfile.Hide();
            //pnlViewCityProfileDetails.Hide();
          
            //pnlViewSupportPersonnelDetails.Hide();

            pnlDeleteMultiCity.Hide();
            pnlDeleteSingleCity.Hide();

            pnlDisplayListOfSupportPersonnelToBeAssigned.Hide();

            //clear all textbox and reset field
            //tbxViewCityProfileSearch.Clear();
            //ViewProfileSearchResult.ClearSelected();
            //lblViewCityID.Text = null;
            //lblViewLvlOfDisasterImpact.Text = null;
            //lblViewNameOfCity.Text = null;
            //lblViewPopulation.Text = null;
            //lblViewShortDescOfDmg.Text = null;
            //lblViewSupportPersonnelRequired.Text = null;

            //DGVViewSP.
            tbxSearchViewSP.Focus();

            try
            {
                DGVViewSP.DataSource = null;
                DGVViewSP.Refresh();
                if (AllFormClass.SupportPersonnels.Count > 0)
                {
                    foreach (SupportPersonnels s in AllFormClass.SupportPersonnels)
                    {
                        AllFormClass.viewAllSP.Add(s);
                    }

                }
                DGVViewSP.DataSource = AllFormClass.viewAllSP;
                DGVViewSP.Refresh();
            }
            catch (NullReferenceException nre)
            {
                return;
            }
        }

        private void tbxSearchViewSP_TextChanged(object sender, EventArgs e)
        {
            if (tbxSearchViewSP.Text != String.Empty)
            {
                String search = tbxSearchViewSP.Text;
                foreach (DataGridViewRow i in DGVViewSP.Rows)
                {
                    i.Selected = false;
                    String searchItem = i.Cells[0].Value.ToString();
                    if (searchItem.Contains(tbxSearchViewSP.Text))
                    {
                        i.Selected = true;
                    }
                    else
                    {
                        i.Selected = false;
                    }
                }
            }
            else
            {
                foreach (DataGridViewRow i in DGVViewSP.Rows)
                {
                    i.Selected = false;
                }
            }
        }

        private void tbxSearchViewCityProfile_TextChanged(object sender, EventArgs e)
        {
            if (tbxSearchViewCityProfile.Text != String.Empty)
            {
                String search = tbxSearchViewCityProfile.Text;
                foreach (DataGridViewRow i in DGVViewCityProfile.Rows)
                {
                    i.Selected = false;
                    String searchItem = i.Cells[1].Value.ToString();
                    if (searchItem.Contains(tbxSearchViewCityProfile.Text))
                    {
                        i.Selected = true;
                    }
                    else
                    {
                        i.Selected = false;
                    }
                }
            }
            else
            {
                foreach (DataGridViewRow i in DGVViewCityProfile.Rows )
                {
                    i.Selected = false;
                }
            }
        }

        private void pnlUpdateSupportPersonnelDetails_Paint(object sender, PaintEventArgs e)
        {

        }

        private void tbxUpdateSupportPersonnelAssignedAffectedCity_TextChanged(object sender, EventArgs e)
        {
            this.listBox1.Items.Clear();

            if (tbxUpdateSupportPersonnelAssignedAffectedCity.Text != String.Empty)
            {
                for (int i = 0; i < AllFormClass.AffectedCity.Count; i++)
                {
                    AffectedCity a =  (AffectedCity)AllFormClass.AffectedCity[i];
                    String searchItem = a.NameOfCity.ToString();
                    if (searchItem.Contains(tbxUpdateSupportPersonnelAssignedAffectedCity.Text))
                    {
                        listBox1.DisplayMember = "NameOfCity";
                        listBox1.Items.Add(a.NameOfCity);
                    }
                }
            }
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
           
        }





        
       

        //copyhere=================================================================================================

        
    }
}
